cmake_minimum_required(VERSION 3.27)
project(MyWebServer)

set(CMAKE_CXX_STANDARD 20)

# 操作系统平台宏
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    message(STATUS "Platform: macOS")
    add_definitions(-DOS_MACOS)
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
    message(STATUS "Platform: Linux")
    add_definitions(-DOS_LINUX)
endif()

# 指定编译选项
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -std=c++11 -O0 -ggdb -Wall -Werror -pthread")

# -rdynamic: 将所有符号都加入到符号表中，便于使用dlopen或者backtrace追踪到符号
# -fPIC: 生成位置无关的代码，便于动态链接
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

# -Wno-unused-function: 不要警告未使用函数
# -Wno-builtin-macro-redefined: 不要警告内置宏重定义，用于重定义内置的__FILE__宏
# -Wno-deprecated: 不要警告过时的特性
# -Wno-deprecated-declarations: 不要警告使用带deprecated属性的变量，类型，函数
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated -Wno-deprecated-declarations")

include_directories(src/include)

set(LIB_SRC
        src/Log.cpp
        src/util.cpp
        src/TcpServer.cpp
        src/ThreadPool.cpp
        src/EventLoop.cpp
        src/Poller.cpp
        src/Connection.cpp
        src/Channel.cpp
        src/Socket.cpp
        src/Buffer.cpp
        src/Acceptor.cpp
)

add_library(myweb SHARED ${LIB_SRC})

add_executable(MyWebServer main.cpp)

add_executable(test_log "tests/test_log.cpp" "${LIB_SRC}")
add_executable(test_utils "tests/test_utils.cpp" "${LIB_SRC}")
add_executable(test_threadpool "tests/test_threadpool.cpp" "${LIB_SRC}")
add_executable(echo_client "tests/echo_client.cpp" "${LIB_SRC}")
add_executable(echo_clients "tests/echo_clients.cpp" "${LIB_SRC}")
add_executable(echo_server "tests/echo_server.cpp" "${LIB_SRC}")

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
